<#if invalid?? && invalid>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong>
	无效的合同信息！
</div>
<#else>
<form class="contract-start-form" action="${request.contextPath}/contract/start" method="post">
	<input type="hidden" name="id" value="${id}" />
	<div class="row">
		<div class="col-md-6">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							项目负责人
						</div>
					</div>
					<select class="form-control not-empty" name="xiangmuHeader">
						<option></option>
						<#if xmh??>
						<#list xmh as h>
						<option value="${h.id}">${h.name}</option>
						</#list>
						</#if>
					</select>
				</div>
			</div>
		</div>
		<div class="col-md-6">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							技经负责人
						</div>
					</div>
					<select class="form-control not-empty" name="jijingHeader">
						<option></option>
						<#if jjh??>
						<#list jjh as h>
						<option value="${h.id}">${h.name}</option>
						</#list>
						</#if>
					</select>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							开工时间
						</div>
					</div>
					<input type="text" class="form-control datetimepicker" name="start" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							完工时间
						</div>
					</div>
					<input type="text" class="form-control datetimepicker" name="end" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-md-4">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">质保金</div>
					</div>
					<input type="hidden" name="money[0].payOut" value="false">
					<input type="hidden" name="money[0].gaveBack" value="false">
					<input type="hidden" name="money[0].inAccount" value="true">
					<input type="hidden" name="money[0].name" value="质保金">
					<input class="money-source" type="hidden" name="money[0].source" value="">
					<input type="hidden" name="money[0].invoice" value="false">
					<input type="text" class="form-control number" name="money[0].total" placeholder="填写金额">
					<div class="input-group-addon">元</div>
				</div>
			</div>
		</div>
		<div class="col-md-4">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">支出日期</div>
					</div>
					<input type="text" class="form-control datetimepicker" name="money[0].time" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-4">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">退还日期</div>
					</div>
					<input type="text" class="form-control datetimepicker" name="money[0].backTime" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-md-4">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">预付款保函</div>
					</div>
					<input type="hidden" name="money[1].payOut" value="false">
					<input type="hidden" name="money[1].gaveBack" value="false">
					<input type="hidden" name="money[1].inAccount" value="true">
					<input type="hidden" name="money[1].name" value="预付款保函">
					<input class="money-source" type="hidden" name="money[1].source" value="">
					<input type="hidden" name="money[1].invoice" value="false">
					<input type="text" class="form-control number" name="money[1].total" placeholder="填写金额">
					<div class="input-group-addon">元</div>
				</div>
			</div>
		</div>
		<div class="col-md-4">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">支出日期</div>
					</div>
					<input type="text" class="form-control datetimepicker" name="money[1].time" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-4">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">退还日期</div>
					</div>
					<input type="text" class="form-control datetimepicker" name="money[1].backTime" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-md-4">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">履约保函</div>
					</div>
					<input type="hidden" name="money[2].payOut" value="false">
					<input type="hidden" name="money[2].gaveBack" value="false">
					<input type="hidden" name="money[2].inAccount" value="true">
					<input type="hidden" name="money[2].name" value="质保金">
					<input class="money-source" type="hidden" name="money[2].source" value="">
					<input type="hidden" name="money[2].invoice" value="false">
					<input type="text" class="form-control number" name="money[2].total" placeholder="填写金额">
					<div class="input-group-addon">元</div>
				</div>
			</div>
		</div>
		<div class="col-md-4">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">支出日期</div>
					</div>
					<input type="text" class="form-control datetimepicker" name="money[2].time" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-4">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">退还日期</div>
					</div>
					<input type="text" class="form-control datetimepicker" name="money[2].backTime" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">备注</div>
					</div>
					<textarea rows="3" class="form-control" name="logRemark" placeholder="最多1000个汉字"></textarea>
				</div>
			</div>
		</div>
	</div>
	<hr>
	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-primary btn-sm btn-submit">确定</div>
			&nbsp;
			<div class="btn btn-default btn-sm" onclick="$.suredy.closeModal();">关闭</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(function() {
		// 初始化日期控件
		$.suredy.datetimepicker.init();

		// 提交表单
		$('.btn.btn-submit').on('click', function() {
			var form = $('form.contract-start-form');

			//判断费用与时间是否都填写
			var m = $('input[name="money[0].total"]').val();
			var t = $('input[name="money[0].time"]').val();
			var b = $('input[name="money[0].backTime"]').val();
			var success = (m === '' && t === '' && b === '') || (m !== '' && t !== '' && b !== '');
			if (!success) {
				alert('[ 质保金 ]必须同时填写金额与日期！');
				return false;
			}
			m = $('input[name="money[1].total"]').val();
			t = $('input[name="money[1].time"]').val();
			b = $('input[name="money[1].backTime"]').val();
			success = (m === '' && t === '' && b === '') || (m !== '' && t !== '' && b !== '');
			if (!success) {
				alert('[ 预付款保函 ]必须同时填写金额与日期！');
				return false;
			}
			m = $('input[name="money[2].total"]').val();
			t = $('input[name="money[2].time"]').val();
			b = $('input[name="money[2].backTime"]').val();
			success = (m === '' && t === '' && b === '') || (m !== '' && t !== '' && b !== '');
			if (!success) {
				alert('[ 履约保函 ]必须同时填写金额与日期！');
				return false;
			}

			// 校验表单
			if (!$.suredy.formChecker(form)) {
				return false;
			}

			var $this = $(this);

			if ($this.hasClass('disabled'))
				return false;

			$this.addClass('disabled');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert(data.msg || '操作失败！');
						$this.removeClass('disabled');
						return false;
					}

					$.suredy.refreshContent('${id}', [ '#tab1' ]);

					$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('操作失败！\n' + errorThrown);
					$this.removeClass('disabled');
					return false;
				}
			});
		});

	});
</script>
</#if>
